import {combineReducers, createStore, applyMiddleware} from "redux";
import createSagaMiddleware from 'redux-saga';
import {watcherSaga} from "./sagas/rootSaga";
import { composeWithDevTools } from 'redux-devtools-extension';

// Import reducers
import userLoginReducer from './reducers/userLogin';
import gqiEditorReducer from './reducers/gqiEditor';
import commonSettings from "./reducers/commonSettings";
import editor from "./reducers/editor";
import errorMessages from "./reducers/errorMessages";
import compositeEditor from "./reducers/compositeEditor";


const reducer = combineReducers({
  userLogin: userLoginReducer,
  gqiEditor: gqiEditorReducer,
  commonSettings: commonSettings,
  editor: editor,
  errorMessages: errorMessages,
  compositeEditor: compositeEditor
})

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];

// With dev tools
const store = createStore( reducer, composeWithDevTools(applyMiddleware(...middleware)));
// Without dev tools
// const store = createStore( reducer, {}, applyMiddleware(...middleware));

sagaMiddleware.run(watcherSaga);

export default store;
